<?php /*a:1:{s:64:"/www/wwwroot/ams/app/admin/view/permissions/permissions_add.html";i:1586520351;}*/ ?>
<!-- 修改密码页面 【弹出层】 -->
<link rel="stylesheet" href="/static/admin/buttons/button.css">
<link rel="stylesheet" href="/static/admin/lib/bootstrap/css/bootstrap.min.css">

<style>
    #edit_password {
        position: relative;
        width: 100%;
        height: 100%;
        text-align: center;
    }

    #up {
        position: absolute;
        width: 100%;
        text-align: center;
    }

    #down {
        position: absolute;
        bottom: 10;
        width: 100%;
        height: 40px;
    }

    table {
        font-size: 16px;
    }

    #table>tr {
        background-color: black;
    }
</style>

<div id="edit_password">
    <div id="up">
        <table id="table" class="table">
            <tr>
                <td>权限名称</td>
                <td>
                    <input type="text" id="name" placeholder="请输入权限名称">
                </td>
                <td style="color:#F00;">*必填</td>
            </tr>

            <tr>
                <td>权限状态</td>
                <td>
                    <select id="status">
                        <?php if(is_array($permissions_status) || $permissions_status instanceof \think\Collection || $permissions_status instanceof \think\Paginator): $i = 0; $__LIST__ = $permissions_status;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$row): $mod = ($i % 2 );++$i;?>
                        <option value="<?php echo htmlentities($row['value']); ?>"><?php echo htmlentities($row['name']); ?></option>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                    </select>
                </td>
                <td style="color:#F00;"></td>
            </tr>

            <tr>
                <td>权限 URL</td>
                <td>
                    <input type="text" id="url" placeholder="请输入权限URL">
                </td>
                <td style="color:#F00;"></td>
            </tr>

            <tr>
                <td>备注</td>
                <td>
                    <textarea id="note" cols="30" rows="3"></textarea>
                </td>
                <td style="color:#F00;"></td>
            </tr>
        </table>
    </div>

    <div id="down">
        <button class="button button-raised button-primary button-pill" onclick="save()">添加</button>
        <button class="button button-raised button-primary button-pill" onclick="back()">返回</button>
    </div>

</div>

<script src="/static/admin/lib/jquery/jquery.js"></script>
<script src="/static/admin/lib/layer/layer.js"></script>
<script>

    // 添加
    function save() {

        var name = $('#name').val().trim();
        var url = $('#url').val().trim();
        var status = $('#status').val().trim();
        var note = $('#note').val().trim();

        if (name.length < 2) {
            return layer.msg('权限名称不少于2位', { icon: 2, time: 900 });
        }
        var data = {
            'name': name,
            'url': url,
            'status': status,
            'note': note
        };

        $.ajax({
            url: "<?php echo url('Permissions/Permissions_add'); ?>",
            data: data,
            type: "POST",
            dataType: "JSON",
            success: function (res) {
                // 返回结果处理
                if (res.code == 0) {
                    return layer.msg(res.msg, { icon: 1, time: 900 }, function () {
                        back();
                    });
                } else {
                    return layer.msg(res.msg, { icon: 2, time: 900 });
                }
            }
        });

    }

    // 返回按钮
    function back() {
        // 获取到父级容器
        var index = parent.layer.getFrameIndex(window.name);
        // 关闭父级容器
        parent.layer.close(index);
    }

</script>